//
//  NSLockDemo.swift
//  sinaDemo
//
//  Created by admin on 2021/7/14.
//

import UIKit
/*
 NSLock就是pthread的OC封装，遵循NSLocking协议，有加锁和解锁方法。用法简单。不再赘述~~~~~~啦啦啦啦
 */
class NSLockDemo: LockBase {
    var lock:NSLock = NSLock.init()
    var lock1:NSLock = NSLock.init()
    override func saleTickets() {
        lock.lock()
        //尝试加锁，没加上也继续执行
//        lock.try()
        //过一定时间后即使加不上锁也会继续执行
//        lock.lock(before: Date.init(timeIntervalSinceNow: 100))
        super.saleTickets()
        lock.unlock()
        
    }
    override func saveMoney() {
        lock1.lock()
        super.saveMoney()
        lock1.unlock()
    }
    override func payMoney() {
        lock1.lock()
        super.payMoney()
        lock1.unlock()
        
    }
}
